package com.hmall.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;



@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private ISearchService searchService;



    @PostMapping("/list")
    public PageDTO<ItemDoc> getItems(@RequestBody RequestParams requestParams) {
        return searchService.qureyItems(requestParams);
    }
    /**
     * 过滤项聚合功能
     * @param requestParams
     * @return
     */
    @PostMapping("/filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParams requestParams) {
        return searchService.getFilters(requestParams);

    }
    /**
     * 搜索框自动补全
     * @param prefix
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> searchSuggestion(@RequestParam("key") String prefix) {
        System.out.println(prefix);
        return searchService.getSuggestion(prefix);
    }
}
